import { Elysia, t } from "elysia";
import { chatCompletions } from "./spark";

export function createHttpRoute(app: Elysia) {
  app
    .get("/", () => "Hello Elysia")
    .group("/webhook", app => {
      return app.post(
        "/event",
        ({ body }) => {
          console.log("🚀 ~ .post ~ body:", body);
          return JSON.stringify({
            challenge: body.challenge,
          });
        },
        {
          body: t.Object({
            challenge: t.String(),
          }),
        }
      );
    })
    // 接入星火大模型
    .get("/chat-completions", async ({ query: { text } }) => {
      const res = await chatCompletions(
        text || "不知道该说点啥，你都会什么呀？"
      );
      return res;
    });
  // .get("/chat-completions", () => {
  //   // TODO: 接入百度千帆
  //   return "Hello World";
  // })
}
